package zelix.hack.hacks;

import zelix.hack.Hack;
import zelix.hack.HackCategory;

import zelix.value.BooleanValue;
import zelix.utils.Wrapper;
import net.minecraft.block.Block;
import net.minecraft.block.BlockAir;
import net.minecraft.client.settings.KeyBinding;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.math.BlockPos;
import net.minecraftforge.fml.common.gameevent.TickEvent.PlayerTickEvent;

public class SafeWalk extends Hack {
	BooleanValue sneak;

	public SafeWalk() {
		super("SafeWalk", HackCategory.MOVEMENT);
		sneak=new BooleanValue("Eagle", false);
		addValue(sneak);
	}

	@Override
	public void onPlayerTick(PlayerTickEvent event) {

		if(sneak.getValue()){
			if(getBlockUnderPlayer(Wrapper.INSTANCE.player()) instanceof BlockAir) {
				if(Wrapper.INSTANCE.player().onGround) {
					KeyBinding.setKeyBindState(Wrapper.INSTANCE.mc().gameSettings.keyBindSneak.getKeyCode(), true);
				}
			} else {
				if(Wrapper.INSTANCE.player().onGround) {
					KeyBinding.setKeyBindState(Wrapper.INSTANCE.mc().gameSettings.keyBindSneak.getKeyCode(), false);
				}
			}
		}
		super.onPlayerTick(event);
	}

	public Block getBlock(BlockPos pos) {
		return Wrapper.INSTANCE.world().getBlockState(pos).getBlock();
	}

	public Block getBlockUnderPlayer(EntityPlayer player) {
		return getBlock(new BlockPos(player.posX , player.posY - 1.0d, player.posZ));
	}
}
